<template>
  <div>
    <h3 v-show="info"> {{ info }}</h3>
    <p>用户名：<input type="text" v-model.trim="username"></p>
    <p>密码：<input type="password" v-model.trim="password"></p>
    <p><button @click="login">登录</button></p>
  </div>
</template>

<script>
export default {
  data(){
    return {
      username: '',
      password: '',
      info: ''
    }
  },
  methods: {
    login(){
      if("lisi" === this.username && "1234" === this.password){
        sessionStorage.setItem("isAuth", true)
        let redirect = this.$route.query.redirect;
        if(redirect){
          this.$router.replace(redirect)
        }
        else{
          this.$router.replace("/")
        }
      }
      else{
        sessionStorage.setItem("isAuth", false)
        this.username = ''
        this.password = ''
        this.info = '用户名或密码错误，请重新登录'
      }
    }
  }
}
</script>

<style>

</style>